//https://www.nowcoder.com/practice/6e196c44c7004d15b1610b9afca8bd88?tpId=13&tqId=23293&ru=/exam/oj/ta&qru=/ta/coding-interviews/question-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D13%26type%3D13
//思路1:遍历出每一颗节点，如果当前节点的的值等于子树的根节点；2.开始逐步遍历各个节点的相等性；
//技巧：1.这里如果int改为double，那么判断相等就需要谨慎,如下； 
// 技巧：使用limit模版;//https://deepinout.com/cpp/cpp-questions/g_difference-between-stdnumeric_limitst-min-max-and-lowest-in-cpp.html
#include <algorithm>
#include <climits>
#include <queue>
#include <vector>
#include <stack> 
#include <limits>

//std::numeric_limits<T>::min()
//std::numeric_limits<T>::max()
//std::numeric_limits<T>::lowest()
//std::numeric_limits<T>::epsilon():表示两个浮点值之间的差值；

bool Equal(double num1,double num2) {
    if((num1-num2 > -0.0000001) && (num1-num2 < 0.0000001)) {
        return true;
    } else {
        return false;
    }
}

bool isEqual(double a, double b) {
    return std::abs(a - b) < std::numeric_limits<double>::epsilon();
}

using namespace std;
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class Solution {
public:
    bool compareSame(TreeNode* pRoot1, TreeNode* pRoot2) {
		if (pRoot2 == nullptr) {
			return true;
		}
		if (pRoot1 == nullptr){
			return false;
		}

		if (pRoot1->val != pRoot2->val) {
			return false;
		}
		if (compareSame(pRoot1->left,pRoot2->left) == false) {
			return false;
		}
		return compareSame(pRoot1->right,pRoot2->right)? true:false;
	}

  bool RecursiveTree1(TreeNode* pRoot1, TreeNode* pRoot2){
		if(pRoot1 == nullptr) {
			return false;
		}
		if(compareSame(pRoot1,pRoot2)) {
			return true;
		} 
		bool res_left = RecursiveTree1(pRoot1->left,pRoot2);
		if (res_left) return true;
		bool res_right = RecursiveTree1(pRoot1->right,pRoot2);
		return res_right;
	}

  bool HasSubtree(TreeNode* pRoot1, TreeNode* pRoot2) {
		if (pRoot1 == nullptr || pRoot2 == nullptr) {
			return false;
		}
		return RecursiveTree1(pRoot1,pRoot2);
    }
};